package com.qf2207.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf2207.bo.WaterPowerPriceBo;
import com.qf2207.mapper.WaterPowerPriceMapper;
import com.qf2207.service.WaterPowerPriceService;
import com.qf2207.vo.BarVo;
import com.qf2207.vo.LayuiPageVo;
import com.qf2207.vo.PieVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/*
 * @Author LX
 * @Date 2022/7/28    8:48
 * @Version 3.3
 */
@Service("/WaterPowerPriceService")
public class WaterPowerPriceServiceImpl implements WaterPowerPriceService{
    @Autowired
    WaterPowerPriceMapper waterPowerPriceMapper;

    @Override
    public LayuiPageVo<WaterPowerPriceBo> WaterPowerPricePageData(Map<String, Object> params) {
        //mybatis 分页插件
        int page = Integer.parseInt(params.get("page") + "");
        int limit = Integer.parseInt(params.get("limit") + "");
        PageHelper.startPage(page,limit);
        List<WaterPowerPriceBo> waterPowerPriceBos = waterPowerPriceMapper.selectByParams(params);

        //mybatis 的分页数据结构
        PageInfo<WaterPowerPriceBo> waterPowerPriceBoPageInfo = new PageInfo<>(waterPowerPriceBos);
        //把mybatis 的分页数据结构封装到 laiui 的分页数据结构中
        LayuiPageVo<WaterPowerPriceBo> powerPriceBoLayuiPageVo = new LayuiPageVo<>();
        powerPriceBoLayuiPageVo.setCode(0);
        powerPriceBoLayuiPageVo.setMsg("分页数据列表");
        powerPriceBoLayuiPageVo.setCount(waterPowerPriceBoPageInfo.getTotal());
        powerPriceBoLayuiPageVo.setData(waterPowerPriceBoPageInfo.getList());
        return powerPriceBoLayuiPageVo;
    }
    @Override
    public List<BarVo> sexBarData() {

        List<BarVo> list = waterPowerPriceMapper.sexBarData();
        return list;
    }

    @Override
    public List<PieVo> sexPieData() {
        List<PieVo> list = waterPowerPriceMapper.sexPieData();
        return list;
    }

    @Override
    public int addWaterPowerPriceBo(WaterPowerPriceBo waterPowerPriceBo) {
        return waterPowerPriceMapper.addWaterPowerPriceBo(waterPowerPriceBo);
    }

    @Override
    public int WaterPowerPriceedit(WaterPowerPriceBo waterPowerPriceBo) {
        return waterPowerPriceMapper.updateByPrimaryKeySelective(waterPowerPriceBo);
    }

    @Override
    public int deleteWaterPowerPrice(Integer id) {
        return waterPowerPriceMapper.deleteByPrimaryKey(id);
    }

}
